package com.demo.zyt.modules.app.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.demo.zyt.common.dto.majorplan.MajorPlanDTO;
import com.demo.zyt.common.exception.RRException;
import com.demo.zyt.common.utils.AppResultEnum;
import com.demo.zyt.common.utils.PageUtils;
import com.demo.zyt.common.utils.Query;
import com.demo.zyt.modules.app.dao.WxQrcodeDao;
import com.demo.zyt.modules.app.entity.WxQrcodeEntity;
import com.demo.zyt.modules.app.service.WxQrcodeService;

@Service("wxQrcodeService")
public class WxQrcodeServiceImpl extends ServiceImpl<WxQrcodeDao, WxQrcodeEntity> implements WxQrcodeService {

	@Override
	public void checkQrCodeName(Integer userId, String qrCodeName) {
		
		EntityWrapper<WxQrcodeEntity> wrapper = new EntityWrapper<>();
		
		wrapper.eq("name", qrCodeName);
		
		wrapper.eq("userid", userId);
		
		List<WxQrcodeEntity> wxQrcodeEntities = this.selectList(wrapper);
		
		if ( wxQrcodeEntities.size() > 0 ) {
			throw new RRException(AppResultEnum.QRCODE_NAME_EXITS);
		}
		
	}

	@Override
	public PageUtils queryByCondition(Map<String, Object> params) {
		Page<WxQrcodeEntity> page = new Query<WxQrcodeEntity>(params).getPage();
		
		List<WxQrcodeEntity> qrcodeEntities = this.baseMapper.queryByCondition(page, params);
		
		
        page.setRecords(qrcodeEntities);
        
        return new PageUtils<WxQrcodeEntity>(page);
	}

}
